import {Injectable} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {Observable} from 'rxjs/Observable';
import {Teacher} from './teacher';

@Injectable()
export class TeacherService {

    url_teacherList = 'Teacher/list/';
    url_teacherAdd = 'Teacher/add';
    url_teacherShow = 'Teacher/show/';
    url_teacherUpdate = 'Teacher/update';
    url_teacherDel = 'Teacher/del';

    constructor(private http: _HttpClient) {
    }

    getlist(id: number): Observable<string> {
        return this.http.get(this.url_teacherList + id);
    }

    delteacher(id: number): Observable<string> {
        return this.http.get(this.url_teacherDel, {id: id});
    }

    getTeacher(id: string): Observable<Teacher> {
        return this.http.get(this.url_teacherShow + id);
    }


    addTeacher(item: Teacher): Observable<string> {
        // const parameter: Teacher = {
        //         id: item.id ? item.id : 0,
        //         username: item.username,
        //         headimg: item.headimg,
        //         tyear: item.tyear,
        //         dyear: item.dyear,
        //         passper: item.passper,
        //         content: item.content
        //     }
        // ;
        console.error(JSON.stringify(item));
        return this.http.post(this.url_teacherAdd, JSON.stringify(item));
    }
}
